package com.cloud.sms.service;

import com.cloud.sms.dao.SmsDefenseCoreMapper;
import com.cloud.sms.interceptor.ServiceException;
import com.cloud.sms.model.SmsDefenseCore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @describe 短信防御业务
 * 
 * @author ruanpeng
 * @date 2014年7月19日
 */
@Service
public class SmsDefenseCoreService {

	@Autowired
	private SmsDefenseCoreMapper smsDefenseCoreMapper;

	public int insertSelective(SmsDefenseCore model){
		int len = 0;
		try {
			len = smsDefenseCoreMapper.insertSelective(model);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return len;
	}

	public int deleteByPrimaryKey(int id) throws ServiceException {
		int len;
		try {
			len = smsDefenseCoreMapper.deleteByPrimaryKey(id);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException();
		}
		return len;
	}

	public int updateByPrimaryKeySelective(SmsDefenseCore model) throws ServiceException {
		int len;
		try {
			len = smsDefenseCoreMapper.updateByPrimaryKeySelective(model);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException();
		}
		return len;
	}

	public SmsDefenseCore selectByPrimaryKey(int id) {
		return smsDefenseCoreMapper.selectByPrimaryKey(id);
	}
	
	public SmsDefenseCore selectByTelephoneNoLast(String telephoneNo) {
		return smsDefenseCoreMapper.selectByTelephoneNoLast(telephoneNo);
	}	

	public int countIpLimit(String ipaddress, String starttime, String endtime){
		int len = 0;
		try {
			Integer counts = smsDefenseCoreMapper.countIpLimit(ipaddress, starttime, endtime);
			if (counts != null) {
				len = counts.intValue();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return len;
	}
	
}
